//
//  MControlSubView.m
//  Mask
//
//  Created by 郭子一 on 2020/10/4.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MControlSubView.h"

@interface MControlSubView ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UISlider *sliderView;
@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *moddleLabel;
@property (nonatomic, strong) UILabel *rightLabel;


@end

@implementation MControlSubView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeUI];
    }
    return self;
}

- (void)makeUI
{
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"压力调节";
    self.titleLabel.font = JSS_FONT_3;
    self.titleLabel.textColor = RGB_VALUE(0x2D3033);
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.centerY.offset(0);
        make.width.mas_equalTo(52);
        make.height.mas_equalTo(18);
    }];
    
    self.sliderView = [[UISlider alloc] init];
    self.sliderView.minimumValue = -100;
    self.sliderView.maximumValue = 100;
    self.sliderView.value = 50;
    // thumbTintColor : 当前滑块的颜色，默认为白色
//    slider.thumbTintColor = [UIColor yellowColor];
    [self.sliderView addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:self.sliderView];
    [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(13);
        make.centerY.offset(0);
        make.right.offset(-20);
        make.height.mas_equalTo(22);
    }];
    
    self.leftLabel = [[UILabel alloc] init];
    self.leftLabel.text = @"-100";
    self.leftLabel.font = JSS_FONT_0;
    self.leftLabel.textColor = RGB_VALUE(0xB6C1C7);
    self.leftLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.leftLabel];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.sliderView.mas_left);
        make.top.equalTo(self.sliderView.mas_bottom).offset(0);
        make.width.mas_equalTo(23);
        make.height.mas_equalTo(14);
    }];
    
    self.moddleLabel = [[UILabel alloc] init];
    self.moddleLabel.text = @"0";
    self.moddleLabel.font = JSS_FONT_0;
    self.moddleLabel.textColor = RGB_VALUE(0xB6C1C7);
    self.moddleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.moddleLabel];
    [self.moddleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.sliderView);
        make.top.equalTo(self.leftLabel).offset(0);
        make.width.mas_equalTo(23);
        make.height.mas_equalTo(14);
    }];
    
    self.rightLabel = [[UILabel alloc] init];
    self.rightLabel.text = @"100";
    self.rightLabel.font = JSS_FONT_0;
    self.rightLabel.textColor = RGB_VALUE(0xB6C1C7);
    self.rightLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.rightLabel];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-21);
        make.top.equalTo(self.leftLabel).offset(0);
        make.width.mas_equalTo(23);
        make.height.mas_equalTo(14);
    }];
}

- (void)sliderChange:(UISlider *)sender
{
    NSLog(@"%f",sender.value);
}
@end
